﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcContrib.Pagination;
using Project.DAL.Repository;

namespace Project.WebUI.Areas.Admin.Controllers
{
    public class UserBetController : Controller
    {
        #region "private"
        private readonly IUserRepository _userRepository;
        private readonly IDepositRepository _depositRepository;
        private readonly IWithDrawRepository _withDrawRepository;
        private readonly IUserService _userService;
        private readonly ICountryRepository _countryRepository;
        private readonly IContactRepository _contactRepository;
        private readonly IBetRepository _betRepository;
        private readonly IUserbetRepository _userbetRepository;
        private readonly IBetDetailRepository _betDetailRepository;
        private readonly IStoreSecureRepositoty _storeSecureRepositoty;

        public UserBetController(
            IUserRepository userRepository,
            IDepositRepository depositRepository,
            IWithDrawRepository withDrawRepository,
            IUserService userService,
            ICountryRepository countryRepository,
            IContactRepository contactRepository, 
            IBetRepository betRepository,
            IUserbetRepository userbetRepository,
            IBetDetailRepository betDetailRepository,
            IStoreSecureRepositoty storeSecureRepositoty)
        {
            _userRepository = userRepository;
            _depositRepository = depositRepository;
            _withDrawRepository = withDrawRepository;
            _userService = userService;
            _countryRepository = countryRepository;
            _contactRepository = contactRepository;
            _betRepository = betRepository;
            _userbetRepository = userbetRepository;
            _betDetailRepository = betDetailRepository;
            _storeSecureRepositoty = storeSecureRepositoty;
        }
        #endregion        

        #region Index
        public ActionResult Index()
        {
            return View();
        }
        #endregion

        #region LoadAjax
        public ActionResult LoadAjax(int page)
        {
            var listUserBet = _userbetRepository.GetMany(null,
                                                       m =>
                                                       m.OrderByDescending(t => t.CreatedTime).ThenBy(s => s.Status),
                                                       "BetDetail,User");
            ViewBag.result = listUserBet.Count();
            ViewBag.page = page;
            if (page == 1)
            {
                ViewBag.start = 0;
            }
            else
            {
                ViewBag.start = (page - 1) * 10;
            }
            return PartialView("_MainContent", listUserBet.AsPagination(page, 10));
        }
        #endregion

        #region UpdateStatus
        public ActionResult UpdateStatus(int id, int status)
        {
            var userBet = _userbetRepository.GetById(id);
            if (status == 1)
            {
                userBet.Status = false;
                _userbetRepository.SaveChanges();
                ViewBag.status = false;
                ViewBag.id = id;
                ViewBag.controller = "UserBet";
                return PartialView("_UpdateStatus");
            }
            userBet.Status = true;
            _userbetRepository.SaveChanges();
            ViewBag.status = true;
            ViewBag.id = id;
            ViewBag.controller = "UserBet";
            return PartialView("_UpdateStatus");
        }
        #endregion

    }
}
